using System;
using Cysharp.Threading.Tasks;
using Framework.Extension.UI.LoopList;
using Framework.Helper;
using Framework.UI;
using Game.System;
using Shared.UI;
using UnityEngine;
using UnityEngine.UI;

namespace Game.Logic.Auth.ServerList
{
    public class ServerListView : UIView
    {
        public LoopListEx llEx;

        public Text txtCurrentServerName;
        public Text txtCurrentServerState;
        public Button btnClose;

        private ServerList serverList;

        private void Start()
        {
            btnClose.AddListener(OnClose);
        }
        
        public override async UniTask RefreshUI()
        {
            serverList = controller as ServerList;
            await UniTask.CompletedTask;
            Debug.Log("_________  " + AccountSystem.Instance.serverList.Count);
            llEx.SetData(AccountSystem.Instance.serverList);
        }

        private async UniTask OnClose()
        {
            await UIManager.Instance.Active<Login.Login>(UIId.Login);
            await serverList.Deactive(serverList.Id);
        }
    }
}